var app = new Vue({
  el: "#deliveryTasklist",
  data() {
    return {
      deliveryType: getUrlParam('id'), // 进行中：0，已完成：1
      deliveryTitle: [
        {
          type: '进行中',
          status: 'DELIVERING'
        },
        {
          type: '已完成',
          status: 'DELIVER_FINISHED'
        }
      ],
      listData: null, // 列表数据
      currentPage: 0, // 当前页数
      totalPage: 2, // 总页数
      loading: false
    }
  },
  methods: {
        // 返回
        goback () {
            window.location.href = "./myTask.html"
        },
        loadMore(){// 滚动加载更多商品
            this.currentPage++
            if(this.currentPage > this.totalPage){
              this.loading = true        
              return false
            }
            this.getListData()
        },
        // 获取数据
        getListData () {
            Axios.post('delivery/deliveryList.do', {communityStatus: this.deliveryTitle[this.deliveryType].status, currentPage: this.currentPage})
                .then(res => {
                    if (res.respCode === 'S') {
                        let list = res.data.data
                        list.forEach(item => {
                            item.actualArriveTime = new Date(item.actualArriveTime).Format('yy-MM-dd hh:mm')
                            item.deliveryFinishTime = new Date(item.deliveryFinishTime).Format('yy-MM-dd hh:mm')
                            item.amount = item.amount / 100 + "元"
                        })
                        if (this.currentPage == 1) {
                            this.listData = list
                        } else {
                            this.listData = this.listData.concat(list)
                        }
                            this.totalPage = res.data.totalPage
                        if (this.currentPage < this.totalPage) {
                            this.loading = false
                        }
                    }
            })
        },
        // 进行中/已完成切换
        changeDeliveryType (index) {
            this.deliveryType = index
            this.currentPage = 1
            this.listData = null
            this.getListData()
        },
        jumpDetail (index) {
            window.location.href = 'deliveryDetail.html?id=' + this.listData[index].ordersId
        }
  }
})